package com.probox.common.entity.service.wechat.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Arrays;
import java.util.List;

import com.probox.common.core.enums.DataStatus;
import com.probox.common.core.utils.SecurityUtils;
import com.probox.common.core.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.probox.common.entity.mapper.wechat.WechatBroadcastProductMapper;
import com.probox.common.entity.domain.wechat.broadcast.WechatBroadcastProduct;
import com.probox.common.entity.service.wechat.IWechatBroadcastProductService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 直播间商品数据Service业务层处理
 *
 * @author usoft
 * @date 2021-07-26
 */
@Service
@Transactional
public class WechatBroadcastProductServiceImpl extends ServiceImpl<WechatBroadcastProductMapper, WechatBroadcastProduct> implements IWechatBroadcastProductService {
    @Autowired
    private WechatBroadcastProductMapper wechatBroadcastProductMapper;


    /**
     * 查询直播间商品数据
     *
     * @param id 直播间商品数据ID
     * @return 直播间商品数据
     */
    @Override
    public WechatBroadcastProduct selectWechatBroadcastProductById(Long id) {
        return this.getById(id);
    }

    /**
     * 查询直播间商品数据列表
     *
     * @param wechatBroadcastProduct 直播间商品数据
     * @return 直播间商品数据
     */
    @Override
    public List<WechatBroadcastProduct> queryList(WechatBroadcastProduct wechatBroadcastProduct) {
        QueryWrapper<WechatBroadcastProduct> queryWrapper = Wrappers.query();
        if (StringUtils.isNotEmpty(String.valueOf(wechatBroadcastProduct.getId())) && wechatBroadcastProduct.getId() != null) {
            queryWrapper.eq("ID", wechatBroadcastProduct.getId());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatBroadcastProduct.getGoodsId())) && wechatBroadcastProduct.getGoodsId() != null) {
            queryWrapper.eq("GOODS_ID", wechatBroadcastProduct.getGoodsId());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatBroadcastProduct.getProductId())) && wechatBroadcastProduct.getProductId() != null) {
            queryWrapper.eq("PRODUCT_ID", wechatBroadcastProduct.getProductId());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatBroadcastProduct.getName())) && wechatBroadcastProduct.getName() != null) {
            queryWrapper.eq("NAME", wechatBroadcastProduct.getName());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatBroadcastProduct.getCoverImgUrl())) && wechatBroadcastProduct.getCoverImgUrl() != null) {
            queryWrapper.eq("COVER_IMG_URL", wechatBroadcastProduct.getCoverImgUrl());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatBroadcastProduct.getPriceType())) && wechatBroadcastProduct.getPriceType() != null) {
            queryWrapper.eq("PRICE_TYPE", wechatBroadcastProduct.getPriceType());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatBroadcastProduct.getPrice())) && wechatBroadcastProduct.getPrice() != null) {
            queryWrapper.eq("PRICE", wechatBroadcastProduct.getPrice());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatBroadcastProduct.getPrice2())) && wechatBroadcastProduct.getPrice2() != null) {
            queryWrapper.eq("PRICE2", wechatBroadcastProduct.getPrice2());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatBroadcastProduct.getUrl())) && wechatBroadcastProduct.getUrl() != null) {
            queryWrapper.eq("url", wechatBroadcastProduct.getUrl());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatBroadcastProduct.getThirdPartyAppid())) && wechatBroadcastProduct.getThirdPartyAppid() != null) {
            queryWrapper.eq("THIRD_PARTY_APPID", wechatBroadcastProduct.getThirdPartyAppid());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatBroadcastProduct.getAuditId())) && wechatBroadcastProduct.getAuditId() != null) {
            queryWrapper.eq("AUDIT_ID", wechatBroadcastProduct.getAuditId());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatBroadcastProduct.getOnSale())) && wechatBroadcastProduct.getOnSale() != null) {
            queryWrapper.eq("ON_SALE", wechatBroadcastProduct.getOnSale());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatBroadcastProduct.getDataStatus())) && wechatBroadcastProduct.getDataStatus() != null) {
            queryWrapper.eq("DATA_STATUS", wechatBroadcastProduct.getDataStatus());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatBroadcastProduct.getCreateUser())) && wechatBroadcastProduct.getCreateUser() != null) {
            queryWrapper.eq("CREATE_USER", wechatBroadcastProduct.getCreateUser());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatBroadcastProduct.getCreateName())) && wechatBroadcastProduct.getCreateName() != null) {
            queryWrapper.eq("CREATE_NAME", wechatBroadcastProduct.getCreateName());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatBroadcastProduct.getUpdateUser())) && wechatBroadcastProduct.getUpdateUser() != null) {
            queryWrapper.eq("UPDATE_USER", wechatBroadcastProduct.getUpdateUser());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatBroadcastProduct.getUpdateName())) && wechatBroadcastProduct.getUpdateName() != null) {
            queryWrapper.eq("UPDATE_NAME", wechatBroadcastProduct.getUpdateName());
        }
        return wechatBroadcastProductMapper.selectList(queryWrapper);
    }

    /**
     * 新增直播间商品数据
     *
     * @param wechatBroadcastProduct 直播间商品数据
     * @return 结果
     */
    @Override
    public boolean insertWechatBroadcastProduct(WechatBroadcastProduct wechatBroadcastProduct) {


        DateTime date = DateUtil.date();
        Long platformId = SecurityUtils.getPlatformId();
        String username = SecurityUtils.getUsername();
        Long userId = SecurityUtils.getUserId();

        wechatBroadcastProduct.setDataStatus(DataStatus.valid.getKey());

        wechatBroadcastProduct.setPlatformUid(platformId);

        wechatBroadcastProduct.setCreateUser(userId);
        wechatBroadcastProduct.setCreateName(username);
        wechatBroadcastProduct.setCreateTime(date);

        wechatBroadcastProduct.setUpdateUser(userId);
        wechatBroadcastProduct.setUpdateName(username);
        wechatBroadcastProduct.setUpdateTime(date);

        return this.save(wechatBroadcastProduct);

    }

    /**
     * 修改直播间商品数据
     *
     * @param wechatBroadcastProduct 直播间商品数据
     * @return 结果
     */
    @Override
    public boolean updateWechatBroadcastProduct(WechatBroadcastProduct wechatBroadcastProduct) {

        return this.updateById(wechatBroadcastProduct);
    }

    /**
     * 批量删除直播间商品数据
     *
     * @param ids 需要删除的直播间商品数据ID
     * @return 结果
     */
    @Override
    public boolean deleteWechatBroadcastProductByIds(Long[] ids) {
        return this.removeByIds(Arrays.asList(ids));
    }


}
